<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>


<head>
    <title>Basic Custom Example</title>

{{include 'pages/base/layout.html'}}


    <script src="{{=URL('static','adminlte/plugins/datepicker/bootstrap-datepicker.js')}}"></script>
    <script src="{{=URL('static','adminlte/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js')}}"></script>
    <link rel="stylesheet" href="{{=URL('static','adminlte/plugins/datepicker/datepicker3.css')}}">

    <script src="{{=URL('static','adminlte/plugins/highcharts/highcharts.js')}}"></script>

    <link rel="stylesheet" href="{{=URL('static','adminlte/plugins/bootstrap-table/bootstrap-table.css')}}"/>
    <link rel="stylesheet" href="{{=URL('static','adminlte/plugins/bootstrap3-editable/css/bootstrap-editable.css')}}"/>
    <script src="{{=URL('static','adminlte/plugins/bootstrap-table/bootstrap-table.js')}}"></script>
    <script src="{{=URL('static','adminlte/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.js')}}"></script>
    <script src="{{=URL('static','adminlte/plugins/bootstrap-table/extensions/editable/bootstrap-table-editable.js')}}"></script>
    <script src="{{=URL('static','adminlte/plugins/bootstrap3-editable/js/bootstrap-editable.js')}}"></script>

</head>

<script language="JavaScript">
    $(document).ready(function(){

        var oTable = new TableInit();
        oTable.Init();

        window.operateEvents = {
           'click .retest': function (e, value, row, index) {
               var retest_url = "{{=URL('alpha','retest')}}"
               retest_url = retest_url + '?policy_id='+row.id
               var path = '<iframe  src=\''+ retest_url + '\' width="100%" height="550px" frameborder="0"></iframe>'
               parent.$("#lgModal").find(".modal-dialog").attr("class", "modal-dialog modal-lg");
               parent.$("#lgModal").find(".modal-body").html(path).end().modal("show");
           },
           'click .perf_attrib': function (e, value, row, index) {
               var retest_url = "{{=URL('alpha','perf_attrib')}}"
               retest_url = retest_url + '?policy_id='+row.id
               var path = '<iframe  src=\''+ retest_url + '\' width="100%" height="550px" frameborder="0"></iframe>'
               parent.$("#lgModal").find(".modal-dialog").attr("class", "modal-dialog modal-lg");
               parent.$("#lgModal").find(".modal-body").html(path).end().modal("show");
           },
           'click .risk_attrib': function (e, value, row, index) {
               var retest_url = "{{=URL('alpha','risk_attrib')}}"
               retest_url = retest_url + '?policy_id='+row.id
               var path = '<iframe  src=\''+ retest_url + '\' width="100%" height="550px" frameborder="0"></iframe>'
               parent.$("#lgModal").find(".modal-dialog").attr("class", "modal-dialog modal-lg");
               parent.$("#lgModal").find(".modal-body").html(path).end().modal("show");
           }
        };

    });

    function add_policy(){
        window.location.href="{{=URL('alpha','mainwizard_v2')}}"
    };


    function update_policy(){
        var sel_policy = $('#tb_departments').bootstrapTable('getSelections');
        if(sel_policy.length == 0){
            alert('请选择要删除的策略')
            return;
        }
        var url = "{{=URL('alpha','mainwizard_v2')}}"
        url = url + "?policy_name=" + sel_policy[0]['policy_name'] + '&policy_id=' + sel_policy[0]['id']
        window.location.href=url
    };

    function del_policy(){
        var sel_policy = $('#tb_departments').bootstrapTable('getSelections');
        if(sel_policy.length == 0){
            alert('请选择要删除的策略')
            return;
        }

        if (confirm("是否确定删除选中策略")){
            parent.$("#loading").show();
            $.ajax({
                type: 'POST',
                async: false,
                url: '{{=URL('alpha_main_v2','remove_policy')}}',
                data: {
                     'policy_id': sel_policy[0]['id'],
                     'policy_name': sel_policy[0]['policy_name']
                },
                success: function (data) {
                    parent.$("#loading").hide();
                    if (data.status == "error") {
                        alert(data.msg)
                    }
                    $('#tb_departments').bootstrapTable('removeByUniqueId', sel_policy[0]['id']);
                }
            });
        }
    };

    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#tb_departments').bootstrapTable({
                url: '{{=URL('alpha_main_v2','get_policy_list')}}', //请求后台的URL（*）
                method: 'get', //请求方式（*）
                toolbar: '#toolbar', //工具按钮用哪个容器
                striped: true, //是否显示行间隔色
                cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: false, //是否显示分页（*）
                sortable: false, //是否启用排序
                sortOrder: "desc", //排序方式
                sortName:"id",
                sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1, //初始化加载第一页，默认第一页
                pageSize: 5, //每页的记录行数（*）
                pageList: [10, 25, 50, 100], //可供选择的每页的行数（*）
                search: false, //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: false,
                showColumns: false, //是否显示所有的列
                showRefresh: false, //是否显示刷新按钮
                //                minimumCountColumns: 2, //最少允许的列数
                clickToSelect: true, //是否启用点击选中行
                //height: 500, //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "id", //每一行的唯一标识，一般为主键列
                showToggle: false, //是否显示详细视图和列表视图的切换按钮
                cardView: false, //是否显示详细视图
                detailView: false, //是否显示父子表
                queryParams: function getParams(params) {
                    var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                            sortOrder: params.order,//排序
                            sortName:params.sort//排序字段
                    };
                    return temp;
                },
                columns: [{
                    radio:true
                },{
                    field: 'id',
                    visible:false
                }, {
                    field: 'policy_name',
                    title: '策略名',
                    sortable : true,
                    width: 100
                }, {
                    field: 'create_date',
                    title: '创建时间',
                    sortable : true,
                    width: 120
                }, {
                    field: 'comb_weights',
                    title: '策略状态',
                    align: 'center',
                    width: 80,
                },{
                       field: 'retest',
                       title: '操作',
                       align: 'center',
                       width: 200,
                       formatter: function (value, row, index) {
                           var a = '<a class = "retest" href="javascript:void(0)">回测&nbsp;&nbsp;&nbsp;</a>';
                           var b = '<a class = "perf_attrib" href="javascript:void(0)">绩效归因&nbsp;&nbsp;&nbsp;</a>';
                           var c = '<a class = "risk_attrib" href="javascript:void(0)">风险归因</a>';
                           return a + b + c;
                       },
                       events: 'operateEvents'
                }]
            });
        };
        return oTableInit;
    };

</script>
<body>
    <div class='container'>
        <div id="toolbar" class="btn-group">
            <button id="btn_add" type="button" class="btn btn-default" onclick="add_policy()">
                <span class="glyphicon glyphicon-plus" aria-hidden="true" ></span>新增
            </button>
            <button id="btn_update" type="button" class="btn btn-default" onclick="update_policy()">
                <span class="glyphicon glyphicon-pencil" aria-hidden="true" ></span>修改
            </button>
            <button id="btn_delete" type="button" class="btn btn-default" onclick="del_policy()">
                <span class="glyphicon glyphicon-remove" aria-hidden="true" ></span>删除
            </button>
        </div>
    <table id="tb_departments"></table>
    </div>
</body>
</html>